<template>
	<view class="myBalance">
		<view class="weui-page__back">
			<image src="https://img.2024csnl.com/static/2.x/a38.png" mode=""></image>
		</view>
		<view class="topBox">
			<view class="back">
				<image src="https://img.2024csnl.com/static/2.x/a51.png" mode=""></image>
			</view>
			<view class="myPoints_total">
				<view class="tag">
					<image src="https://img.2024csnl.com/static/2.x/a52.png" mode=""></image>
					<text>泌豆商城</text>
				</view>
				
				<view class="money">
					<view class="label">
						<text>泌豆余额</text>
					</view>
					<view class="value">
						<image src="https://img.2024csnl.com/static/2.x/a39.png" mode=""></image>
						<text>{{jifen}}</text>
					</view>
				</view>
				
				<view class="explain">
					<text>泌豆可用于购买商品和兑换贡献值</text>
				</view>
				
				<view class="exchange_btn" v-if="false">
					<view class="" @click="onSkip('/pages/goods/integral-mall')">泌豆兑换</view>
					<view style="margin-left: 100rpx;" v-if="showType==1" @click="onSkip('/package/mine/transition/transition?tabsActive=1&person=true')">转赠</view>
				</view>
				<view
					class="rule"
					@click="open('popup')">
					<image src="https://img.2024csnl.com/static/2.x/a49.png" mode=""></image>
					<text>泌豆规则</text>
				</view>
			</view>
		</view>
		
		<view class="page-thead">
			<text>泌豆明细</text>
		</view>
		
		<view class="details-box">
			<view class="list">
				<view class="item"
					v-for="(item,index) in list"
					:key="index">
					<view class="cell">
						<view class="left">
							<view class="name">{{item.remark}}</view>
							<view class="time">{{item.time}}</view>
						</view>
						<view class="right">
							<view :class="{
								'money': true,
								'is-red': item.score > 0
							}">
								<text>{{ item.score }}</text>
							</view>
						</view>
					</view>
				</view>
				
				<view class="" v-if="list.length==0">
					<image src="https://wx.2024csnl.com/static/noData.png"></image>
					暂无数据~
				</view>
				
				<view style="text-align: center;color: #999;" v-if="noMoreData&&list.length!=0">没有更多啦~</view>
			</view>
		</view>
		
		<uni-popup ref="popup" type="center">
			<view class="hintModalBox">
				<view class="title">泌豆规则</view>
				<view class="hint">
					<text>{{rule}}</text>
				</view>
				<view class="btn flex-center" @click="close('popup')">确认</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	// #ifdef APP-PLUS
	import ADMixin from '../../../utils/ad.js';
	// #endif
	import {
		getShoppingDetails,
		getIntegrationRule
	} from "../../../api/index.js"
	export default {
		// #ifdef APP-PLUS
		mixins: [ADMixin],
		// #endif
		data() {
			return {
				showType:null,
				jifen: 0,
				list: [],
				rule: '',
				pagenum: 1,
				totalPage: '',
				noMoreData: false,
			};
		},
		onLoad(opt) {
			this.showType=opt.type
			this.onGetShoppingDetails()
			this.onGetIntegrationRule()
		},
		onReachBottom() {
			if (this.pagenum < this.totalPage) {
				this.pagenum += 1
				this.onGetShoppingDetails('bottom')
			} else {
				this.noMoreData = true
			}
		},
		methods: {
			async onGetShoppingDetails(type) {
				const res = await getShoppingDetails('s=/ApiScoreshop/scoremx', {
					page: this.pagenum
				})
				const {
					msg,
					data,
					status,
					jifen,
				} = res.data
				console.log(res,"res")
				if (status == 1) {
					this.jifen = jifen
					this.totalPage = data.last_page
					type == 'bottom' ? this.list.push(...data.data) : this.list = data.data
					this.pagenum != 1 && data.length == 0 ? this.noMoreData = true : this.noMoreData = false
				} else {
					this.showToast(msg)
				}
			},
			open(n) {
				this.$refs[n].open();
			},
			close(n) {
				this.$refs[n].close();
			},
			async onGetIntegrationRule() {
				const res = await getIntegrationRule('s=/ApiScoreshop/scoresm')
				const {
					msg,
					data,
					status
				} = res.data
				// console.log(res, "res---")
				if (status == 1) {
					this.rule = data

				} else {
					this.showToast(msg)
				}
			},

		}
	}
</script>

<style lang="scss">
	.myBalance {
		min-height: 100vh;
		background: #f8f8f8;
		.topBox {
			position: relative;
			margin: 0 30rpx 80rpx;
			padding: 40rpx;
			top: 80rpx;
			border-radius: 20rpx;
			overflow: hidden;
			.back {
				position: absolute;
				left: 0;
				top: 0;
				right: 0;
				bottom: 0;
				z-index: 0;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.tag {
				position: absolute;
				left: -30rpx;
				top: 30rpx;
				background: linear-gradient( 180deg, #FF8652 7%, #E76730 99%);
				box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0,0,0,0.1);
				border-radius: 0rpx 8rpx 32rpx 0rpx;
				display: flex;
				align-items: center;
				padding: 20rpx 40rpx 20rpx 30rpx;
				image {
					display: block;
					width: 36rpx;
					height: 36rpx;
					margin-right: 10rpx;
				}
				text {
					color: #ffffff;
				}
			}
			.rule {
				position: absolute;
				right: 0;
				top: 0;
				padding: 30rpx 30rpx;
				display: flex;
				align-items: center;
				image {
					display: block;
					width: 40rpx;
					height: 40rpx;
					margin-right: 4rpx;
				}
				text {
					color: #999;
				}
			}
			.money {
				position: relative;
				padding: 0 20rpx;
				margin-top: 40rpx;
				.label {
					line-height: 40rpx;
					font-size: 30rpx;
					color: #999;
					visibility: hidden;
				}
				.value {
					line-height: 80rpx;
					font-size: 56rpx;
					color: #41644A;
					font-weight: bold;
					display: flex;
					align-items: center;
					image {
						display: block;
						width: 50rpx;
						height: 50rpx;
						margin-right: 10rpx;
					}
				}
			}
			.explain {
				margin-top: 40rpx;
				line-height: 40rpx;
				color: #999;
			}
			.btns {
				display: flex;
				align-items: center;
				margin-top: 20rpx;
				.cell {
					flex: 1;
				}
				.btn {
					height: 80rpx;
					line-height: 80rpx;
					border-radius: 80rpx;
					margin: 20rpx;
					background: #41644A;
					text-align: center;
					font-size: 34rpx;
					font-weight: bold;
					color: #ffffff;
					&.is-chongzhi {
						background: -webkit-linear-gradient(left, #2D4834, #FFA47B);
					}
				}
			}
		}
	}
	
	
	
	.page-thead {
		line-height: 100rpx;
		padding: 0 30rpx;
		font-size: 30rpx;
		color: #999;
	}
	
	.details-box {
		margin: 0 30rpx;
		background: #ffffff;
		border-radius: 20rpx;
		.tabs {
			display: flex;
			align-items: center;
			.item {
				position: relative;
				&.is-active {
					&:before {
						visibility: visible;
					}
					text {
						color: #2D4834;
						font-weight: bold;
					}
				}
				text {
					display: block;
					position: relative;
					z-index: 2;
					height: 100rpx;
					line-height: 100rpx;
					padding: 0 40rpx;
					font-size: 32rpx;
					color: #999;
				}
				&:before {
					content: '';
					position: absolute;
					z-index: 0;
					left: 20rpx;
					top: 60rpx;
					width: 120rpx;
					height: 18rpx;
					border-radius: 20rpx;
					background: -webkit-linear-gradient(left, #FDD69F, #ffffff);
					visibility: hidden;
				}
			}
		}
		.list {
			// border-top: 1px solid #eeeeee;
			margin: 0 20rpx;
			.item {
				& + .item {
					border-top: 1px solid #eeeeee;
				}
				.cell {
					display: flex;
					align-items: center;
					padding: 30rpx 0;
				}
				.avatar {
					image {
						display: block;
						width: 100rpx;
						height: 100rpx;
						background: #eeeeee;
						border-radius: 50%;
					}
				}
				.left {
					flex: 1;
					margin: 0 20rpx;
					.name {
						line-height: 60rpx;
						font-size: 30rpx;
						font-weight: bold;
					}
					.time {
						line-height: 40rpx;
						color: #999;
					}
				}
				.right {
					text-align: right;
					.money {
						line-height: 60rpx;
						font-size: 34rpx;
						&.is-red {
							color: #E76730;
							&:before {
								content: '+';
							}
						}
					}
					.yue {
						line-height: 40rpx;
						color: #999;
					}
				}
			}
		}
	}
	
	.hintModalBox {
		background: #fff;
		width: 80vw;
		border-radius: 20rpx;
		text-align: center;
		.title {
			padding: 30rpx;
			font-size: 30rpx;
		}
		.hint {
			padding: 0 30rpx 30rpx;
			line-height: 40rpx;
			color: #999999;
		}
		.btn {
			height: 100rpx;
			line-height: 100rpx;
			font-size: 32rpx;
			font-weight: bold;
			border-top: 1px solid #eeeeee;
		}
	}
</style>
